// 蜂窝蜜造平台生成代码，如手工更改，请添加到 .beeignore 忽略生成

package com.fowo.api.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ReflectUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.read.listener.ReadListener;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fowo.api.common.annotaion.DataObjectType;
import com.fowo.api.common.config.CacheConfig;
import com.fowo.api.common.excel.ExcelConfig;
import com.fowo.api.common.model.OptionItem;
import com.fowo.api.common.util.ContextHolder;
import com.fowo.api.common.util.ResponseUtils;
import com.fowo.api.entity.Warehouse;
import com.fowo.api.flow.entity.WorkFlow;
import com.fowo.api.flow.service.WorkFlowService;
import com.fowo.api.mapper.LogisticslevelMapper;
import com.fowo.api.mapper.WarehouseMapper;
import com.fowo.api.model.logisticslevel.LogisticslevelSearchParamPo;
import com.fowo.api.model.warehouse.WarehouseAddBinAction;
import com.fowo.api.model.warehouse.WarehouseBatchAddBinAction;
import com.fowo.api.model.warehouse.WarehouseBinExport1Action;
import com.fowo.api.model.warehouse.WarehouseBinExportimportAction;
import com.fowo.api.model.warehouse.WarehouseBinandProductexportAction;
import com.fowo.api.model.warehouse.WarehouseBinimportProductAction;
import com.fowo.api.model.warehouse.WarehouseFBABinVo;
import com.fowo.api.model.warehouse.WarehouseItemVo;
import com.fowo.api.model.warehouse.WarehouseLocalAndOverseasVo;
import com.fowo.api.model.warehouse.WarehouseSearchParamPo;
import com.fowo.api.model.warehouse.WarehouseVo;
import com.fowo.api.service.LogisticslevelService;
import com.fowo.api.service.WarehouseService;
import com.fowo.api.sys.annotation.DataActivity;
import com.fowo.api.sys.component.ExecuteScriptEngine;
import com.fowo.api.sys.entity.enums.SysDataActivityAction;
import com.fowo.api.user.model.JwtUserInfo;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import javax.validation.Validator;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;

/**
 * 仓库 服务实现基类
 * @author 蜂窝蜜造平台 配置人：王阳阳
 */
@Slf4j
@DataObjectType(Warehouse.class)
@DS("ds24")
public class WarehouseBaseServiceImpl
  extends ServiceImpl<WarehouseMapper, Warehouse>
  implements WarehouseService {

  /** 引用字段排序字段名转换信息 */
  public static final Map<String, String> SORT_FIELD_MAP = new HashMap<>() {
    {
      put("supplierIdSupplierName", "s.`supplier_name`");
    }
  };

  /**
   * 服务自引用，用于调用服务方法时包括 AOP 处理
   */
  @Resource
  protected WarehouseService self;

  @Resource
  protected LogisticslevelService logisticslevelService;

  @Resource
  protected WorkFlowService workFlowService;

  @Autowired(required = false)
  protected WarehouseAddBinAction warehouseAddBinAction;

  @Autowired(required = false)
  protected WarehouseBatchAddBinAction warehouseBatchAddBinAction;

  @Autowired(required = false)
  protected WarehouseBinExport1Action warehouseBinExport1Action;

  @Autowired(required = false)
  protected WarehouseBinExportimportAction warehouseBinExportimportAction;

  @Autowired(required = false)
  protected WarehouseBinandProductexportAction warehouseBinandProductexportAction;

  @Autowired(required = false)
  protected WarehouseBinimportProductAction warehouseBinimportProductAction;

  @Resource
  private ExecuteScriptEngine executeScriptEngine;

  @Resource
  protected Validator validator;

  /**
   * 创建仓库
   * @param model 仓库
   * @return 新数据的主键
   */
  @DataActivity(action = SysDataActivityAction.Add)
  @Transactional(rollbackFor = Exception.class)
  @Override
  public Long create(WarehouseVo model) throws Exception {
    JwtUserInfo currentUser = JwtUserInfo.fromHeader();
    Warehouse entity = new Warehouse();
    BeanUtils.copyProperties(model, entity);
    entity.setCreateTime(new Date());
    entity.setLastUpdateTime(new Date());
    if (currentUser != null) {
      entity.setCreateUser(currentUser.getUserId());
      entity.setLastUpdateUser(currentUser.getUserId());
    }
    if (this.save(entity)) {
      model.setId(entity.getId());
      updateAllChilds(model);
      return entity.getId();
    }
    throw new Exception("仓库保存失败");
  }

  /**
   * 更新所有子表
   * @param model 仓库
   */
  protected void updateAllChilds(WarehouseVo model) throws Exception {
    if (model.getLogisticslevel() != null) {
      logisticslevelService.saveAllByParentWarehouse(
        model.getId(),
        model.getLogisticslevel()
      );
    }
  }

  /**
   * 更新仓库
   * @param model 仓库
   * @return 更新是否成功
   */
  @DataActivity(action = SysDataActivityAction.Modified)
  @Override
  @Transactional(rollbackFor = Exception.class)
  public boolean update(WarehouseVo model) throws Exception {
    JwtUserInfo currentUser = JwtUserInfo.fromHeader();
    Warehouse entity = this.getById(model.getId());
    if (entity == null) {
      throw new Exception("仓库不存在");
    }
    BeanUtils.copyProperties(
      model,
      entity,
      "id",
      "createTime",
      "createUser",
      "lastUpdateTime",
      "lastUpdateUser"
    );
    entity.setLastUpdateTime(new Date());
    if (currentUser != null) {
      entity.setLastUpdateUser(currentUser.getUserId());
    }
    if (this.updateById(entity)) {
      updateAllChilds(model);
      return true;
    }
    return false;
  }/**
   * 更新仓库（带空值）
   * @param model 仓库
   * @return 更新是否成功
   */

  @DataActivity(action = SysDataActivityAction.Modified)
  @Override
  @Transactional(rollbackFor = Exception.class)
  public boolean updateForEdit(WarehouseVo model) throws Exception {
    JwtUserInfo currentUser = JwtUserInfo.fromHeader();
    Warehouse entity = this.getById(model.getId());
    if (entity == null) {
      throw new Exception("仓库不存在");
    }
    model.setLastUpdateTime(new Date());
    if (currentUser != null) {
      model.setLastUpdateUser(currentUser.getUserId());
    }
    boolean isOk = new LambdaUpdateChainWrapper<>(baseMapper)
      .set(Warehouse::getName, model.getName())
      .set(Warehouse::getWidType, model.getWidType())
      .set(Warehouse::getLastUpdateTime, model.getLastUpdateTime())
      .set(Warehouse::getLastUpdateUser, model.getLastUpdateUser())
      .set(Warehouse::getRemark, model.getRemark())
      .set(Warehouse::getSid, model.getSid())
      .eq(Warehouse::getId, model.getId())
      .update();
    if (isOk) {
      updateAllChilds(model);
    }
    return isOk;
  }

  /**
   * 是否走导出中心
   */
  @Override
  public boolean getBackgroundExportFlag(WarehouseSearchParamPo search) {
    return false;
  }

  /**
   * 批量删除指定主键列表关联的所有子表数据(此方法不包括事务，必须由其它已包括事务的方法调用)
   */
  protected void batchDeleteChilds(List<Long> ids) throws Exception {
    // 处理子表字段 物流等级(logisticslevel) 对应的对象
    LogisticslevelSearchParamPo logisticslevelSearchParam =
      new LogisticslevelSearchParamPo();
    logisticslevelSearchParam.setDisableDataPremissions(true);
    logisticslevelSearchParam.setParentWarehouseInList(ids);
    LogisticslevelMapper localLogisticslevelMapper = ContextHolder
      .getApplicationContext()
      .getBean(LogisticslevelMapper.class);
    logisticslevelSearchParam.applySqlSegments();
    List<Long> logisticslevelIdList = localLogisticslevelMapper.searchIds(
      logisticslevelSearchParam
    );
    if (!logisticslevelIdList.isEmpty()) {
      LogisticslevelService localLogisticslevelService = ContextHolder
        .getApplicationContext()
        .getBean(LogisticslevelService.class);
      localLogisticslevelService.batchDelete(logisticslevelIdList);
    }
  }

  /**
   * 删除仓库
   * @param id 仓库的主键
   * @return 删除是否成功
   */
  @DataActivity(action = SysDataActivityAction.Del)
  @Override
  public boolean delete(Long id) throws Exception {
    batchDeleteChilds(Collections.singletonList(id));
    return this.removeById(id);
  }

  /**
   * 批量删除仓库
   * @param ids 仓库的主键列表
   * @return 删除是否成功
   */
  @DataActivity(action = SysDataActivityAction.Del)
  @Override
  public boolean batchDelete(List<Long> ids) throws Exception {
    batchDeleteChilds(ids);

    int count = 0;
    for (int i = 0; i < ids.size(); i += 2000) {
      count +=
        baseMapper.deleteBatchIds(
          ids.stream().skip(i).limit(2000).collect(Collectors.toList())
        );
    }
    return count > 0;
  }

  /**
   * 通过仓库名称查询仓库主键(重复时返回最新的主键)
   */
  @Override
  public Long getIdByName(String name) {
    return this.baseMapper.getIdByName(name);
  }

  /**
   * 通过仓库名称查询仓库多主键(重复时返回最新的主键)
   */
  @Override
  public List<Long> getIdsByName(List<String> list) {
    return this.baseMapper.getIdsByName(list);
  }

  /**
   * 通过仓库主键查询仓库名称
   */
  @Override
  public String getNameById(Long id) {
    return this.baseMapper.getNameById(id);
  }

  /**
   * 通过仓库主键查询仓库名称列表
   */
  @Override
  public List<String> getNameByIds(List<Long> ids) {
    List<Map<String, Object>> maps = this.baseMapper.getNameByIds(ids);
    // 将返回重新排列为输入相同顺序
    return ids
      .stream()
      .map(id -> {
        Optional<Map<String, Object>> optionalMap = maps
          .stream()
          .filter(map -> id.equals(map.get("id")))
          .findFirst();
        return optionalMap
          .map(stringObjectMap -> (String) stringObjectMap.get("name"))
          .orElse(null);
      })
      .collect(Collectors.toList());
  }

  /**
   * 获取详情
   * @param id 仓库的主键
   */
  @DataActivity(action = SysDataActivityAction.View)
  @Override
  public WarehouseVo getVoById(Long id) throws Exception {
    WarehouseVo vo = this.baseMapper.selectVoById(id);
    if (vo == null) {
      return null;
    }

    LogisticslevelSearchParamPo logisticslevelSearchParamPo =
      new LogisticslevelSearchParamPo();
    logisticslevelSearchParamPo.setParentWarehouse(id);
    logisticslevelSearchParamPo.getExtendData().put("queryMode", "sub");
    logisticslevelSearchParamPo.getExtendData().put("queryParent", "Warehouse");
    logisticslevelSearchParamPo.applySqlSegments();
    vo.setLogisticslevel(
      logisticslevelService.search(logisticslevelSearchParamPo)
    );

    return vo;
  }

  /**
   * 分页查询仓库
   * @param search 查询条件
   * @return 仓库分页查询结果
   */
  @Override
  public Page<WarehouseItemVo> pageSearch(WarehouseSearchParamPo search) {
    Page<WarehouseItemVo> page = new Page<>();
    if (
      Objects.nonNull(search.getWfStatus()) &&
      StringUtils.hasText(search.getFormName())
    ) {
      List<WorkFlow> workFlowList = workFlowService.queryWfListByStatus(
        search.getWfStatus(),
        search.getFormName()
      );
      if (CollectionUtils.isEmpty(workFlowList)) {
        return page;
      }
      List<Long> ids = workFlowList
        .stream()
        .map(WorkFlow::getRecordId)
        .collect(Collectors.toList());
      if (CollectionUtils.isEmpty(ids)) {
        return page;
      }
      search.setSelectedIds(ids);
    }
    search.initSort("t.id desc", "t.", SORT_FIELD_MAP);
    page = this.baseMapper.pageSearch(search.toPage(), search);
    List<Long> recordIds = page
      .getRecords()
      .stream()
      .map(WarehouseItemVo::getId)
      .collect(Collectors.toList());
    if (CollectionUtils.isEmpty(recordIds)) {
      return page;
    }
    List<WorkFlow> workFlows = workFlowService.queryWfList(
      recordIds,
      Collections.singletonList(search.getFormName())
    );
    if (CollectionUtils.isEmpty(workFlows)) {
      return page;
    }
    Map<Long, Integer> flowMap = workFlows
      .stream()
      .collect(Collectors.toMap(WorkFlow::getRecordId, WorkFlow::getWfStatus));
    page
      .getRecords()
      .stream()
      .forEach(item -> {
        if (!flowMap.containsKey(item.getId())) {
          return;
        }
        item.setWfStatus(flowMap.get(item.getId()));
      });
    return page;
  }

  /**
   * 仓库快速查询选项(有缓存)
   * @param search 查询条件
   * @return 选项结果
   */
  @Override
  @Cacheable(
    value = CacheConfig.FAST,
    key = "'WarehouseOptions::' + @userInfo.userTypeAndId + '::' + #search.keyword"
  )
  public List<OptionItem<WarehouseItemVo>> searchOptions(
    WarehouseSearchParamPo search
  ) {
    search.initSort("t.id desc", "t.", SORT_FIELD_MAP);
    return this.baseMapper.searchOptions(search);
  }

  /**
   * 列表查询仓库
   * @param search 查询条件
   * @return 仓库列表查询结果
   */
  @Override
  public List<WarehouseItemVo> search(WarehouseSearchParamPo search) {
    search.initSort("t.id desc", "t.", SORT_FIELD_MAP);
    return this.baseMapper.search(search);
  }

  /**
   * 查询仓库最后更新时间
   * @param search 查询条件
   * @return 仓库最后更新时间
   */
  @Override
  public Date searchLastUpdateTime(WarehouseSearchParamPo search) {
    return this.baseMapper.searchLastUpdateTime(search);
  }

  /**
   * 新增仓位
   */
  @DataActivity(
    action = SysDataActivityAction.Other,
    message = "%s执行了新增仓位操作"
  )
  @Override
  public void addBin() throws Exception {
    if (warehouseAddBinAction == null) {
      throw new Exception("此操作当前不可用");
    }
    warehouseAddBinAction.run();
  }

  /**
   * 批量新增仓位
   */
  @DataActivity(
    action = SysDataActivityAction.Other,
    message = "%s执行了批量新增仓位操作"
  )
  @Override
  public void batchAddBin() throws Exception {
    if (warehouseBatchAddBinAction == null) {
      throw new Exception("此操作当前不可用");
    }
    warehouseBatchAddBinAction.run();
  }

  /**
   * 仓位导出
   */
  @DataActivity(
    action = SysDataActivityAction.Other,
    message = "%s执行了仓位导出操作"
  )
  @Override
  public void binExport1() throws Exception {
    if (warehouseBinExport1Action == null) {
      throw new Exception("此操作当前不可用");
    }
    warehouseBinExport1Action.run();
  }

  /**
   * 仓位导入
   */
  @DataActivity(
    action = SysDataActivityAction.Other,
    message = "%s执行了仓位导入操作"
  )
  @Override
  public void binExportimport() throws Exception {
    if (warehouseBinExportimportAction == null) {
      throw new Exception("此操作当前不可用");
    }
    warehouseBinExportimportAction.run();
  }

  /**
   * 仓位与商品关系导出
   */
  @DataActivity(
    action = SysDataActivityAction.Other,
    message = "%s执行了仓位与商品关系导出操作"
  )
  @Override
  public void binandProductexport() throws Exception {
    if (warehouseBinandProductexportAction == null) {
      throw new Exception("此操作当前不可用");
    }
    warehouseBinandProductexportAction.run();
  }

  /**
   * 仓位与商品关系导入
   */
  @DataActivity(
    action = SysDataActivityAction.Other,
    message = "%s执行了仓位与商品关系导入操作"
  )
  @Override
  public void binimportProduct() throws Exception {
    if (warehouseBinimportProductAction == null) {
      throw new Exception("此操作当前不可用");
    }
    warehouseBinimportProductAction.run();
  }

  /**
   * 同步领星仓库数据
   */
  @DataActivity(
    action = SysDataActivityAction.Other,
    message = "%s执行了同步领星仓库数据操作"
  )
  @Transactional(rollbackFor = Exception.class)
  @Override
  public void syncware() throws Exception {
    executeScriptEngine.callJsInResource(
      "scripts/Warehouse_syncware.js",
      null,
      null,
      this
    );
  }

  /**
   * 本地仓与海外仓
   */
  @Override
  public List<WarehouseLocalAndOverseasVo> localAndOverseas(
    WarehouseSearchParamPo search
  ) {
    search.initSort("t.id desc", "t.", SORT_FIELD_MAP);
    return this.baseMapper.localAndOverseas(search);
  }

  /**
   * 本地仓与海外仓分页
   */
  @Override
  public Page<WarehouseLocalAndOverseasVo> localAndOverseasPage(
    WarehouseSearchParamPo search
  ) {
    Page<WarehouseLocalAndOverseasVo> localAndOverseasPage = new Page<>();
    if (
      Objects.nonNull(search.getWfStatus()) &&
      StringUtils.hasText(search.getFormName())
    ) {
      List<WorkFlow> workFlowList = workFlowService.queryWfListByStatus(
        search.getWfStatus(),
        search.getFormName()
      );
      if (CollectionUtils.isEmpty(workFlowList)) {
        return localAndOverseasPage;
      }
      List<Long> ids = workFlowList
        .stream()
        .map(WorkFlow::getRecordId)
        .collect(Collectors.toList());
      if (CollectionUtils.isEmpty(ids)) {
        return localAndOverseasPage;
      }
      search.setSelectedIds(ids);
    }
    search.initSort("t.id desc", "t.", SORT_FIELD_MAP);
    localAndOverseasPage =
      this.baseMapper.localAndOverseasPage(
          search.toPage(this.baseMapper.localAndOverseasCount(search)),
          search
        );
    List<Long> recordIds = localAndOverseasPage
      .getRecords()
      .stream()
      .map(WarehouseLocalAndOverseasVo::getId)
      .collect(Collectors.toList());
    if (CollectionUtils.isEmpty(recordIds)) {
      return localAndOverseasPage;
    }
    List<WorkFlow> workFlows = workFlowService.queryWfList(
      recordIds,
      Collections.singletonList(search.getFormName())
    );
    if (CollectionUtils.isEmpty(workFlows)) {
      return localAndOverseasPage;
    }
    Map<Long, Integer> flowMap = workFlows
      .stream()
      .collect(Collectors.toMap(WorkFlow::getRecordId, WorkFlow::getWfStatus));
    localAndOverseasPage
      .getRecords()
      .stream()
      .forEach(item -> {
        if (!flowMap.containsKey(item.getId())) {
          return;
        }
        item.setWfStatus(flowMap.get(item.getId()));
      });

    return localAndOverseasPage;
  }

  /**
   * 查询本地仓与海外仓最后更新时间
   * @param search 查询条件
   * @return 本地仓与海外仓最后更新时间
   */
  @Override
  public Date localAndOverseasLastUpdateTime(WarehouseSearchParamPo search) {
    return this.baseMapper.localAndOverseasLastUpdateTime(search);
  }

  /**
   * FBA仓
   */
  @Override
  public List<WarehouseFBABinVo> fBABin(WarehouseSearchParamPo search) {
    search.initSort("t.id desc", "t.", SORT_FIELD_MAP);
    return this.baseMapper.fBABin(search);
  }

  /**
   * FBA仓分页
   */
  @Override
  public Page<WarehouseFBABinVo> fBABinPage(WarehouseSearchParamPo search) {
    Page<WarehouseFBABinVo> fBABinPage = new Page<>();
    if (
      Objects.nonNull(search.getWfStatus()) &&
      StringUtils.hasText(search.getFormName())
    ) {
      List<WorkFlow> workFlowList = workFlowService.queryWfListByStatus(
        search.getWfStatus(),
        search.getFormName()
      );
      if (CollectionUtils.isEmpty(workFlowList)) {
        return fBABinPage;
      }
      List<Long> ids = workFlowList
        .stream()
        .map(WorkFlow::getRecordId)
        .collect(Collectors.toList());
      if (CollectionUtils.isEmpty(ids)) {
        return fBABinPage;
      }
      search.setSelectedIds(ids);
    }
    search.initSort("t.id desc", "t.", SORT_FIELD_MAP);
    fBABinPage =
      this.baseMapper.fBABinPage(
          search.toPage(this.baseMapper.fBABinCount(search)),
          search
        );
    List<Long> recordIds = fBABinPage
      .getRecords()
      .stream()
      .map(WarehouseFBABinVo::getId)
      .collect(Collectors.toList());
    if (CollectionUtils.isEmpty(recordIds)) {
      return fBABinPage;
    }
    List<WorkFlow> workFlows = workFlowService.queryWfList(
      recordIds,
      Collections.singletonList(search.getFormName())
    );
    if (CollectionUtils.isEmpty(workFlows)) {
      return fBABinPage;
    }
    Map<Long, Integer> flowMap = workFlows
      .stream()
      .collect(Collectors.toMap(WorkFlow::getRecordId, WorkFlow::getWfStatus));
    fBABinPage
      .getRecords()
      .stream()
      .forEach(item -> {
        if (!flowMap.containsKey(item.getId())) {
          return;
        }
        item.setWfStatus(flowMap.get(item.getId()));
      });

    return fBABinPage;
  }

  /**
   * 查询FBA仓最后更新时间
   * @param search 查询条件
   * @return FBA仓最后更新时间
   */
  @Override
  public Date fBABinLastUpdateTime(WarehouseSearchParamPo search) {
    return this.baseMapper.fBABinLastUpdateTime(search);
  }

  /**
   * 选择用视图
   */
  @Override
  public List<WarehouseItemVo> selectHide(WarehouseSearchParamPo search) {
    search.initSort("t.id desc", "t.", SORT_FIELD_MAP);
    return this.baseMapper.selectHide(search);
  }

  /**
   * 选择用视图分页
   */
  @Override
  public Page<WarehouseItemVo> selectHidePage(WarehouseSearchParamPo search) {
    Page<WarehouseItemVo> selectHidePage = new Page<>();
    if (
      Objects.nonNull(search.getWfStatus()) &&
      StringUtils.hasText(search.getFormName())
    ) {
      List<WorkFlow> workFlowList = workFlowService.queryWfListByStatus(
        search.getWfStatus(),
        search.getFormName()
      );
      if (CollectionUtils.isEmpty(workFlowList)) {
        return selectHidePage;
      }
      List<Long> ids = workFlowList
        .stream()
        .map(WorkFlow::getRecordId)
        .collect(Collectors.toList());
      if (CollectionUtils.isEmpty(ids)) {
        return selectHidePage;
      }
      search.setSelectedIds(ids);
    }
    search.initSort("t.id desc", "t.", SORT_FIELD_MAP);
    selectHidePage =
      this.baseMapper.selectHidePage(
          search.toPage(this.baseMapper.selectHideCount(search)),
          search
        );
    List<Long> recordIds = selectHidePage
      .getRecords()
      .stream()
      .map(WarehouseItemVo::getId)
      .collect(Collectors.toList());
    if (CollectionUtils.isEmpty(recordIds)) {
      return selectHidePage;
    }
    List<WorkFlow> workFlows = workFlowService.queryWfList(
      recordIds,
      Collections.singletonList(search.getFormName())
    );
    if (CollectionUtils.isEmpty(workFlows)) {
      return selectHidePage;
    }
    Map<Long, Integer> flowMap = workFlows
      .stream()
      .collect(Collectors.toMap(WorkFlow::getRecordId, WorkFlow::getWfStatus));
    selectHidePage
      .getRecords()
      .stream()
      .forEach(item -> {
        if (!flowMap.containsKey(item.getId())) {
          return;
        }
        item.setWfStatus(flowMap.get(item.getId()));
      });

    return selectHidePage;
  }

  /**
   * 查询选择用视图最后更新时间
   * @param search 查询条件
   * @return 选择用视图最后更新时间
   */
  @Override
  public Date selectHideLastUpdateTime(WarehouseSearchParamPo search) {
    return this.baseMapper.selectHideLastUpdateTime(search);
  }
}
